import java.util.NoSuchElementException;

class ArrayQueue {
    private int[] elements;
    private int front;
    private int rear;
    private int size;

    // 构造函数，初始化队列容量
    public ArrayQueue(int capacity) {
        elements = new int[capacity];
        front = 0;
        rear = 0;
        size = 0;
    }

    // 入队操作
    public void enqueue(int value) {
        if (size == elements.length) {
            throw new IllegalStateException("队列已满");
        }
        elements[rear] = value;
        rear = (rear + 1) % elements.length;
        size++;
    }

    // 出队操作
    public int dequeue() {
        if (size == 0) {
            throw new NoSuchElementException("队列为空");
        }
        int result = elements[front];
        front = (front + 1) % elements.length;
        size--;
        return result;
    }

    // 获取队列当前元素值并打印
    public void printQueue() {
        if (size == 0) {
            System.out.println("队列当前没有元素");
            return;
        }
        for (int i = front; i < front + size; i++) {
            System.out.print(elements[i % elements.length] + " ");
        }
        System.out.println();
    }

    // 获取队首元素
    public int peek() {
        if (size == 0) {
            throw new NoSuchElementException("队列为空");
        }
        return elements[front];
    }
}